package bcnet.batch;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class AddPriceMass {

	public static void main(String args[]) {
		HttpURLConnection connection = null, connection2 = null;
		URL url = null; 
		try{
			String fromYear = "2014";
			String fromMonth = "07"; // 00=Jan, 01=Feb, 11=Dec
			String fromDate = "29";
			String toYear = "2014";
			String toMonth = "07"; // 00=Jan, 01=Feb, 11=Dec
			String toDate = "29";
	
			StringBuffer sb = new StringBuffer();
			sb.append("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,75,76,77,78,79,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,135,136,137,138,139,141,142,143,144,145,146,147,148,149,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,193,194,195,196,197,198,199,200,201,202,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,302,303,305,306,307,308,309,311,312,313,315,316,317,"); sb.append("318,319,320,321,322,323,326,327,328,329,330,332,333,334,335,336,337,338,340,341,342,343,345,346,347,348,350,351,352,353,354,355,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,395,396,397,398,399,400,401,402,403,404,406,408,410,411,412,413,417,418,419,420,421,422,423,425,426,430,431,432,433,434,438,439,440,444,445,449,450,451,455,456,458,459,460,462,464,465,467,468,469,471,472,474,475,476,477,479,480,482,483,484,485,486,487,488,489,491,493,494,495,496,497,498,499,500,503,505,506,508,509,510,511,512,513,515,516,517,518,519,521,522,524,525,526,527,528,529,530,531,532,533,535,536,538,539,540,542,543,544,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,563,564,565,566,567,568,569,570,571,572,573,575,576,577,578,579,580,581,582,583,585,586,587,588,589,590,591,592,593,595,596,598,599,600,601,602,603,604,605,606,607,608,609,610,611,613,616,617,618,619,620,621,622,623,626,627,628,629,630,631,632,633,635,636,637,638,639,640,641,642,643,645,646,647,648,650,651,653,655,656,657,658,659,660,661,662,663,665,668,669,670,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,"); sb.append("689,690,691,692,693,694,695,696,697,698,700,701,702,703,704,705,706,707,708,709,710,711,712,713,715,716,717,718,719,720,723,724,725,726,727,728,729,730,731,732,733,735,736,737,738,743,745,746,747,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,769,771,773,775,776,777,787,789,794,798,800,801,802,803,805,806,809,811,812,813,814,815,816,817,818,819,821,822,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,844,845,846,847,848,850,851,852,853,854,855,856,857,858,859,860,861,862,864,865,866,867,868,869,871,872,873,874,875,876,877,878,880,881,882,883,884,885,886,887,888,889,891,893,894,895,896,897,898,899,900,902,903,904,906,907,908,909,910,911,912,914,915,916,917,918,919,921,922,923,925,926,927,928,929,930,931,933,934,935,936,938,939,940,941,943,945,947,948,950,951,952,953,954,956,958,959,960,963,966,967,968,969,970,973,975,976,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1013,1019,1020,1021,1023,1025,1026,1028,1029,1030,1031,1033,1036,1037,1038,1039,1041,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1055,1057,1058,1059,1060,1061,1063,1064,1065,1066,1068,1069,1070,1071,1072,1073,1075,1076,1079,"); sb.append("1080,1082,1083,1085,1086,1087,1088,1089,1090,1091,1093,1094,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1114,1115,1116,1117,1118,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1135,1136,1137,1138,1139,1141,1142,1143,1145,1146,1148,1149,1150,1151,1152,1155,1157,1159,1161,1163,1164,1165,1166,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1180,1181,1182,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1198,1199,1200,1201,1202,1203,1205,1206,1207,1208,1210,1211,1212,1213,1215,1218,1219,1220,1221,1222,1223,1224,1225,1228,1229,1230,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1246,1247,1249,1250,1251,1252,1253,1255,1258,1259,1260,1262,1263,1265,1266,1268,1269,1270,1271,1273,1277,1278,1280,1281,1282,1288,1290,1292,1293,1296,1297,1298,1299,1300,1302,1303,1308,1312,1313,1314,1315,1316,1318,1319,1321,1322,1323,1328,1329,1330,1332,1333,1335,1336,1338,1339,1340,1345,1348,1349,1353,1355,1358,1359,1360,1361,1363,1365,1366,1367,1368,1369,1370,1371,1372,1373,1375,1378,1380,1382,1383,1385,1386,1387,1388,1390,1393,1396,1397,1398,1399,1400,1418,1421,1428,1431,1432,1439,1446,1448,1450,1488,1513,1515,1522,1555,1588,1599,1600,1613,1616,1618,1619,1622,1623,1626,1628,1636,1638,1639,1661,1663,1666,1668,1678,1680,1681,1682,1685,1689,1698,1699,1700,1708,1717,1728,1733,1738,1766,1768,1771,1777,1778,1788,1798,1800,1803,1808,1812,1813,1818,1819,1822,1823,1828,1829,1830,1831,1833,1836,1838,1848,1856,1862,1863,"); sb.append("1866,1868,1878,1880,1882,1883,1884,1886,1888,1889,1893,1898,1899,1900,1908,1910,1913,1918,1919,1928,1929,1938,1963,1966,1968,1972,1980,1988,1991,1998,1999,2000,2002,2005,2006,2007,2008,2009,2010,2011,2012,2014,2018,2020,2023,2028,2030,2033,2038,2039,2068,2078,2080,2083,2088,2098,2099,2100,2111,2112,2118,2121,2123,2128,2133,2168,2178,2183,2186,2188,2196,2198,2200,2202,2208,2211,2213,2218,2222,2223,2226,2228,2229,2233,2236,2238,2255,2266,2268,2282,2283,2288,2298,2299,2300,2302,2303,2307,2308,2309,2310,2313,2314,2317,2318,2319,2320,2322,2323,2326,2327,2328,2329,2330,2331,2333,2336,2338,2339,2340,2341,2342,2343,2345,2348,2349,2355,2356,2357,2358,2362,2366,2368,2369,2371,2378,2379,2380,2382,2383,2386,2388,2389,2393,2398,2399,2468,2488,2600,2601,2607,2608,2618,2623,2626,2628,2638,2662,2668,2678,2688,2689,2698,2700,2722,2727,2728,2777,2788,2789,2866,2868,2877,2878,2880,2882,2883,2886,2888,2889,2898,2899,2922,2923,2924,2929,2930,3300,3303,3308,3311,3313,3315,3318,3322,3323,3328,3330,3331,3332,3333,3335,3336,3337,3339,3344,3355,3360,3363,3366,3368,3369,3377,3378,3380,3382,3383,3386,3389,3393,3398,3399,3608,3618,3623,3628,3633,3636,3639,3663,3666,3668,3669,3683,3688,3698,3709,3777,3778,3788,3800,3808,3813,3816,3818,3823,3828,3833,3836,3838,3868,3883,3886,3888,3889,3898,3899,3900,3903,3918,3933,3939,3948,3968,3983,3988,3989,3993,3998,3999,6030,6123,6128,6136,6138,6139,6166,6168,6188,6198,6199,6808,6818,6823,6828,6830,6837,6838,6863,6868,6880,6881,6883,6888,6889,6898,6899");
			
			
			
			/*
			List<Integer> codeArr = new ArrayList<Integer>();
	        FileReader fr = new FileReader("C:\\Users\\ed98\\Documents\\bcn_in.txt");
	        BufferedReader br = new BufferedReader(fr);
	        String s;
	        while((s = br.readLine()) != null){
	        	codeArr.add(Integer.parseInt(s));
	        }
	        fr.close();
	        */
			
			
			String[] codeArr;
			codeArr = sb.toString().split(",");
	
			
			
			for(int i=0; i<codeArr.length;i++){
				// Create connection
				//for(int j=0;j<400;j++){
				//System.out.println(codeArr[i]);
				
				url = new URL("http://localhost:8888/addPriceMass.jsp?code="
						+ codeArr[i] 
						+ "&fromYear=" + fromYear
						+ "&fromMonth=" + fromMonth
						+ "&fromDate=" + fromDate
						+ "&toYear=" + toYear
						+ "&toMonth=" + toMonth
						+ "&toDate=" + toDate
						);
						
				//url = new URL("http://localhost:8888/addPrice.jsp?code="+codeArr[i]+"&priceDate=2014-01-01&closePrice=1.1");
				
				connection = (HttpURLConnection) url.openConnection();
				
				connection.setRequestMethod("GET");
				connection.setRequestProperty("Content-Type",
						"text/plain; charset=utf-8");
				connection.setRequestProperty("Content-Length",
						"" + Integer.toString("".getBytes().length));
				connection.setRequestProperty("Content-Language", "en-US");
				connection.setUseCaches(false);
				connection.setDoInput(true);
				connection.setDoOutput(true);
	
				// Send request
				DataOutputStream wr = new DataOutputStream(
						connection.getOutputStream());
				wr.writeBytes("");
				wr.flush();
				wr.close();
	
				// Get Response
				InputStream is = connection.getInputStream();
				BufferedReader rd = new BufferedReader(new InputStreamReader(is));
				String line;
				// StringBuffer response = new StringBuffer();
				while ((line = rd.readLine()) != null) {
				}
				rd.close();
	
				//}
			}
		}catch (Exception e) {
			//System.out.println(url.toString());
			e.printStackTrace();

		} finally {

			if (connection != null) {
				connection.disconnect();
			}
			if (connection2 != null) {
				connection2.disconnect();
			}
		}
		
	}
}